<?php

Yii::import('common.models._base.BaseCourseEarlyDiscount');

class CourseEarlyDiscount extends BaseCourseEarlyDiscount
{
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
	
    public $MaxdicountAmount;
    public $MaxdicountPercxentage;

    public static function findMaxDscountByCourse($courseId) {
        $criteria = new CDbCriteria;
        $criteria->select = 'Max(discount_price) as MaxdicountAmount,Max(in_percentage) as MaxdicountPercxentage';
        $criteria->condition = 'courses_id=' . $courseId;
        $maxPrice = CourseEarlyDiscount::model()->find($criteria);       
            if ($maxPrice['MaxdicountAmount'] != '' && $maxPrice['MaxdicountPercxentage'] != '') {
                return('Upto' . $maxPrice['MaxdicountAmount'] >= $maxPrice['MaxdicountPercxentage']) ? '<span class="rupee">'.number_format($maxPrice['MaxdicountAmount'], 2) : number_format($maxPrice['MaxdicountPercxentage'], 2) . ' % Discount </span>';
            }else{
                return 'No Discount';
        }
    }	
	
}